-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Add note about not needing jsx-no-undef with TS / typescript-eslint #3941
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
It's recommended to avoid this rule if your project: | ||
|
||
1. does not use JSX | ||
2. uses TypeScript, which [automatically enables better checks than ESLint `no-undef` rules](https://typescript-eslint.io/troubleshooting/faqs/eslint/#i-get-errors-from-the-no-undef-rule-about-global-variables-not-being-defined-even-though-there-are-no-typescript-errors) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
item 2 and 3 are basically the same - it would be a very bad idea to turn off this rule and NOT enable the typescript-eslint rule.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, well following the advice from the typescript-eslint docs, actually the no-undef
rule should be disabled in TypeScript files
So option 3 is for files where TS type checking is disabled, eg. JS files in a typescript-eslint project
If that doesn't make sense, I can try re-explaining
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah, hmm, ok - which version of TS enabled these better checks? (because TS definitely did not used to do a better job than this rule)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good question, I'm thinking that this was like this from pretty early on... can't remember a time when TS didn't give me errors for undefined JSX element identifiers 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @ljharb, hope everything is going well! 👋
Quick PR to add an additional 2 cases of when to not use
react/jsx-no-undef
when using TypeScript, since it has better checks than ESLint
no-undef
rulesthe
@typescript-eslint/parser
parser allows for usage of ESLint's built-inno-undef
withoutreact/jsx-no-undef
:This applies to:
.tsx
files (as demonstrated in the typescript-eslint Playground link).jsx
or.js
files - also without"allowJs": true
or"checkJs": true
intsconfig.json
.